import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: import('@/views/Layout/index.vue'),
      children:[
        {
          path: '',
          name: 'home',
          component: import('@/views/Home/index.vue')
        },
        {
          path:'/category/:id',
          name:'category',
          component:import('@/views/Category/index.vue')
        },
        {
          path:'/category/sub/:id',
          name:'subCategory',
          component:import('@/views/SubCategory/index.vue')
        },
        {
          path:'/product/:id',
          name:'product',
          component:import('@/views/Product/index.vue')
        },
        {
          path:'/cart',
          name:'cart',
          component:import('@/views/Cart/index.vue')
        },
        {
          path:'/check',
          name:'check',
          component:import('@/views/Check/index.vue')
        },
        {
          path:'/member',
          name:'member',
          component:import('@/views/Member/index.vue')
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: import('@/views/Login/index.vue')
    }
  ],

})

router.beforeEach((to, from, next) => {
  scrollTo({ top: 0});
  next()
})
export default router
